package leetcode.array;

/**
 * @author wangmaolin1
 * @date 2022/1/5 下午11:19
 */
public class _26删除有序数组中的重复项 {

    public static int removeDuplicates(int[] nums) {
        if (nums.length <= 1) {
            return 1;
        }
        int slow = 1;
        int fast = 1;
        while (fast < nums.length) {
            if (nums[fast] != nums[fast - 1]) {
                nums[slow] = nums[fast];
                slow++;
            }
            fast++;
        }
        return slow;

    }

    public int removeDuplicates2(int[] nums) {
        if (nums == null || nums.length <= 0) {
            return 0;
        }
        int res=0;
        int p=0;
        while (p<nums.length){
            if(nums[p]==nums[res]){
                p++;
                continue;
            }
            nums[++res]=nums[p++];
        }
        return res+1;
    }

}
